package com.jeasonzhao.report.vml.base;


public class Vector2D
{
    private int x = -1,y = -1;
    public Vector2D()
    {
        super();
    }

    public Vector2D(int nX,int nY)
    {
        x = nX;
        y = nY;
    }

    public Vector2D(Vector2D v)
    {
        x = v.x;
        y = v.y;
    }

    public int getX()
    {
        return x;
    }

    public int getY()
    {
        return y;
    }

    public int getWidth()
    {
        return x;
    }

    public Vector2D offset(int nx,int ny)
    {
        x = nx + x;
        y = ny + y;
        return this;
    }

    public Vector2D offsetCopy(int nx,int ny)
    {
        return new Vector2D(nx + x,ny + y);
    }

    public Vector2D expandCopy(int nx,int ny)
    {
        return new Vector2D(nx + x,ny + y);
    }

    public Vector2D expand(int nx,int ny)
    {
        x = nx + x;
        y = ny + y;
        return this;
    }

    public int getHeight()
    {
        return y;
    }

    public void setX(int x)
    {
        this.x = x;
    }

    public void setY(int y)
    {
        this.y = y;
    }

    public void setWidth(int x)
    {
        this.x = x;
    }

    public void setHeight(int y)
    {
        this.y = y;
    }

    public String toString()
    {
        return x + "," + y;
    }

    public int area()
    {
        return x * y;
    }

    public static Vector2D getCenter(Vector2D pt1,Vector2D pt2)
    {
        if(pt1 == null || pt2 == null)
        {
            return pt1 == null ? pt2 : pt1;
        }
        return new Vector2D((pt1.getX() + pt2.getX()) / 2,(pt1.getY() + pt2.getY()) / 2);
    }
}
